package com.company.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.persistence.Page;
import com.base.common.service.CrudService;
import com.base.common.utils.SQLUtil;
import com.company.dao.CompanyEmployeeFeeMapper;
import com.company.model.CompanyEmployee;
import com.company.model.CompanyEmployeeFee;
import com.company.service.EmployeeFeeService;

@Service
public class EmployeeFeeServiceImpl extends
		CrudService<CompanyEmployeeFeeMapper, CompanyEmployeeFee> implements
		EmployeeFeeService {

	public Page findEmployeeFeeByCompanyId(String companyId, Page page)
			throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT e.name,e.station,e.department,e.company_id,e.entry_date,e.departure_date,f.oper_date,f.wage,f.welfare,f.other_Charge,f.id from company_employee e , company_employee_fee f where e.id = f.employee_id and e.company_Id = #{companyId} ";
		page = this.getPage(page, sql, CompanyEmployeeFee.class, params);
		return page;
	}
	
	public List<CompanyEmployeeFee> findEmployeeFeeByCompanyId(String companyId)
			throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT e.name,e.station,e.department,e.company_id,e.entry_date,e.departure_date,f.oper_date,f.wage,f.welfare,f.other_Charge,f.id from company_employee e , company_employee_fee f where e.id = f.employee_id and e.company_Id = #{companyId} ";
		List<CompanyEmployeeFee> list = this.getList(sql, CompanyEmployeeFee.class, params);
		return list;
	}

	@Override
	public boolean saveEmployeeFee(CompanyEmployeeFee companyEmployeeFee)
			throws Exception {
		int res = this.saveOrUpdate(companyEmployeeFee);
		return true;
	}
	
	public boolean deleteEmployeeFeeByIds(String ids) throws Exception {
		String sql = "delete from company_Employee_fee where id in ("
				+ SQLUtil.createInStr(ids) + ") ";
		int res = this.delete(sql);
		return true;
	}
	
	public CompanyEmployeeFee findEmployeeFeeById(String id) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		String sql = "SELECT e.name,e.station,e.department,e.company_id,e.entry_date,e.departure_date,f.oper_date,f.wage,f.welfare,f.other_Charge,f.id,f.employee_Id from company_employee e , company_employee_fee f where e.id = f.employee_id and f.id = #{id} ";
		CompanyEmployeeFee companyEmployeeFee = this.getOne(sql, CompanyEmployeeFee.class, params);
		return companyEmployeeFee;
	}
}
